package com.yxhl.zoume.core.func.appraisal.ui.adapter;

import android.databinding.DataBindingUtil;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.yxhl.zoume.AppraisalLabelItem;
import com.yxhl.zoume.R;
import com.yxhl.zoume.common.adapter.BaseAdapter;
import com.yxhl.zoume.data.http.model.appraisal.AppraisalLabel;
import com.yxhl.zoume.utils.CollectionUtils;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by vhawk on 16/9/19.
 */
public class AppraisalLabelConformAdapter extends BaseAdapter<AppraisalLabelConformAdapter.AppraisalLabelViewHolder> {

    private static final String TAG = "AppraisalLabelAdapter";
    private List<AppraisalLabel> labels;

    public AppraisalLabelConformAdapter(List<AppraisalLabel> labels) {
        this.labels = labels;
    }

    @Override
    public AppraisalLabelViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        AppraisalLabelItem appraisalLabelItem = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_appraisal_label, parent, false);
        return new AppraisalLabelViewHolder(appraisalLabelItem);
    }

    @Override
    public void onBindViewHolder(AppraisalLabelViewHolder holder, int position) {
        holder.bindTo(labels.get(position));
    }

    @Override
    public int getItemCount() {
        if (!CollectionUtils.isEmpty(labels)) {
            return labels.size();
        } else {
            return 0;
        }
    }

    public List<String> getLabelList() {
        List<String> labelIds = new ArrayList<>();
        for (AppraisalLabel appraisalLabel : labels) {
            if (appraisalLabel.getSelectedStatus()) {
                labelIds.add(appraisalLabel.getId() + "");
            }
        }
        return labelIds;
    }

    public class AppraisalLabelViewHolder extends BaseAdapter.BaseViewHolder {
        AppraisalLabelItem appraisalLabelDataBinding;

        public AppraisalLabelViewHolder(AppraisalLabelItem appraisalLabelItem) {
            super(appraisalLabelItem.getRoot());
            appraisalLabelDataBinding = appraisalLabelItem;
        }

        public void bindTo(AppraisalLabel appraisalLabel) {
            appraisalLabelDataBinding.setAppraisalLabel(appraisalLabel);
        }
    }
}
